package com.bigflexlib.x.mx.collections.IList.op
{
	
	import mx.collections.IList;
	import mx.events.CollectionEvent;


	public class ListFirstOp extends AbstractListOp
	{
		
		
		private var iValueHandler:Function;
		
		
		private var lastValue:*;		
		
		
		public function ListFirstOp( iList:IList, iValueHandler:Function )
		{
			super( iList );
		
			this.iValueHandler = iValueHandler;
			
			refresh( );
			
		}
		
		
		
		private function refresh( ):void
		{
			
			var newValue:* = iList.length == 0 ? undefined : iList.getItemAt( 0 );
			
			if ( newValue !== lastValue )
			{
				lastValue = newValue
				
				iValueHandler.call( null, newValue );
			
			}
			
		}
		
		
		
		override protected function iList_collectionChange( event:CollectionEvent ):void
		{
			
			refresh( );		
		
		}
		
		
		
		override public function dispose( ):void
		{
		
			super.dispose( );
			
			iValueHandler = null;
		
		}
		
		

	}
	
}